//
//  ViewController.swift
//  yimiao
//
//  Created by mac on 16/3/30.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var cycle = 0
    var score = 0.0
    var god = 0
    var common = 0
    var timeone = NSDate()
    var time = 0.0
    
    @IBOutlet weak var background: UIImageView!
    @IBOutlet weak var commonCycleLabel: UILabel!
    @IBOutlet weak var godCycleLabel: UILabel!
    @IBOutlet weak var cycleLabel: UILabel!
    @IBOutlet weak var tipLabel: UILabel!
    @IBAction func ftouchDown(sender: UIButton) {
        timeone = NSDate()
    }
    @IBOutlet weak var wordLabel: UILabel!
    @IBAction func touchUpInside(sender: AnyObject) {
        let timetwo = NSDate()
        time = timetwo.timeIntervalSinceDate(timeone)
       let timeo = String(format: "%.2f", arguments: [time])
    
        cycle++
        cycleLabel.text = "\(cycle)"
        score = abs(time - 1)
        think()
        tipLabel.text = "你点了" + timeo + "秒"
        tipLabel.textColor = UIColor .blackColor()

    }
    
    
    func think() {
            if score < 0.1{
                god++
                godCycleLabel.text = "\(god)"
                background.image = UIImage(named: "cool_bg")
                wordLabel.text = "great,你是大神"
        
        } else {
                common++
                commonCycleLabel.text = "\(common)"
                background.image = UIImage(named: "default_bg")
                wordLabel.text = "ok,你是平民"
                
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

